<?php include load_tpl('header');?>

<p id="breadcrumbs">
    <a href="/">首页</a> <b>»</b> 
    <span>分类列表</span>
</p>
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
  <div class="heading">
    <h1 style="background-image: url('./images/category.png');">分类列表</h1>
	</div>
	 <div class="content">
	<table class="list">
	<thead>
    <tr height="22" align="center">
        <th width="4%" ><input type="checkbox" name="checkall"></th>
		<th width="6%">分类ID</th>
        <th width="20%">分类名称</th>
        <th width="23%">分类描述</th>
        <th width="10%">启用/禁用</th>
        <th>操作选项</th>
      </tr>
	  </thead>
	  <tbody>
   <?php if($cat_list):
			foreach($cat_list as $cat):
	?>
     <tr align="center" bgcolor="#FFFFFF" height="20" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
        <td><input type="checkbox" name="cid1" id="cid1" value="<?php echo $cat['category_id'];?>" class="np" /></td>
		    <td><?=$cat['category_id']?></td>
        <td><?=$cat['name']?></td>
        <td><?=$cat['description']?></td>
        <td><?php if($cat['status']==1) echo '启用';else echo '禁用';?></td>
        <td>
		<?php if($Category->getCategoryByPid($cat['category_id'])):?>
        <a class="button" href="index.php?mod=category&act=list&pid=<?=$cat['category_id']?>"><span>查看下级分类</span></a>
		<?endif;?>
        <a class="button" href="index.php?mod=category&act=edit&id=<?=$cat['category_id']?>"><span>修改分类</span></a>
        <a class="button" href="index.php?mod=category&act=add&pid=<?=$cat['category_id']?>"><span>添加分类</span></a>
        <a class="button" href="index.php?mod=category&act=del&id=<?=$cat['category_id']?>"><span>删除分类</span></a>
       </td>
      </tr>
	<?php endforeach;?>
	   <tr>
		<td colspan="5" style="text-align: left;">
			
					<a class="button" id="delBtn"><span>删除</span></a>
					<a class="button" id="disBtn"><span>禁用</span></a>
					<a class="button" id="ableBtn"><span>启用</span></a>
				</td>
				<td style="text-align: right;"><?php if(isset($pages))echo $pages;?></td>
		
	  </tr>
	 </tbody>
	<?php else: ?>
	<tr  bgcolor="#FFFFFF">
	<td colspan="6">没有分类！</td>
	</tr>
	<?php endif;?>
</table>
  </div>
</div>

<?php include load_tpl('footer');?>

<script type="text/javascript">
var arr = [];
$(document).ready(function() {
	$("#tableOne thead tr th:first input:checkbox").click(function() {
		var checkedStatus = this.checked;
		$("#tableOne tbody tr td:first-child input:checkbox").each(function() {
			this.checked = checkedStatus;
			if(checkedStatus){
				arr.push(this.value);
			}else{
				arr.pop(this.value);
			}
		});
	});
	$("#tableOne tbody tr td:first-child input:checkbox").click(function() {
		if(this.checked){
			arr.push(this.value);
		}else{
			arr.pop(this.value);
		}
	});
	$("#delBtn").click(function(){
		if(arr.length == 0){
			alert("请先选择!");
			return ;
		}
		window.location.href = "index.php?mod=category&act=del&id="+arr.join(",");
	});
	$("#disBtn").click(function(){
		if(arr.length == 0){
			alert("请先选择!");
			return ;
		}
		window.location.href = "index.php?mod=category&act=edit&go=disable&ids="+arr.join(",");
	});
	$("#ableBtn").click(function(){
		if(arr.length == 0){
			alert("请先选择!");
			return ;
		}
		window.location.href = "index.php?mod=category&act=edit&go=able&ids="+arr.join(",");
	});
});
</script>